#include "mytitlebar.h"
#include "ui_mytitlebar.h"

mytitlebar::mytitlebar(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::mytitlebar)
{
    ui->setupUi(this);

    //m_parent = parent;
}

mytitlebar::~mytitlebar()
{
    delete ui;
}

void mytitlebar::setmyParent(QWidget *parent)
{
    m_parent = parent;
}

void mytitlebar::mouseMoveEvent(QMouseEvent *event)
{
    //持续状态下，要判断是否有其他按键存在
    //左键  001   001
    //右键  002   010
    //中键  004   100
    if(event->buttons() & Qt::LeftButton )
    {
        //Oldpoint - OldparentTopleft = Newpoint - NewparentTopleft;
        //求接下来父窗口左上角要移动到的位置：NewparentTopleft = Newpoint - m_pt;
        m_parent->move(event->globalPos() - m_pt);
    }
}

void mytitlebar::mousePressEvent(QMouseEvent *event)
{
    //判定瞬间状态下是否是鼠标左键
    if(event->button() == Qt::LeftButton)
    {
        //求点击位置相对于父窗口左上角的距离m_pt = Oldpoint - OldparentTopleft
        m_pt = event->globalPos() - m_parent->geometry().topLeft();
    }

}

void mytitlebar::on_setBtn_clicked()
{
    emit showSetWindow();
}


void mytitlebar::on_minBtn_clicked()
{
    emit showMinWindow();
}


void mytitlebar::on_closeBtn_clicked()
{
    emit closeMyWindow();
}

